package com.central.generator.utils;

import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.collection.ListUtil;
import cn.hutool.core.io.FileUtil;
import cn.hutool.core.map.MapUtil;
import cn.hutool.poi.excel.ExcelUtil;
import lombok.val;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.scheduling.annotation.AsyncResult;

import java.util.*;
import java.util.concurrent.Future;
import java.util.concurrent.FutureTask;

/**
 * @description:
 * @author: qiu
 * @param:
 * @create: 2022-06-17
 **/
public class FileUtils {
    public static void main(String[] args) {
        List<String> strings = FileUtil.readLines("C:\\Users\\admin\\Desktop\\log\\2\\catalina.out.2022-06-22", "Utf-8");
        strings.addAll(FileUtil.readLines("C:\\Users\\admin\\Desktop\\log\\2\\catalina.out.2022-06-23", "Utf-8"));

        Map<String,Object> errorMap = new HashMap<>();
        List<String> errorStr = new ArrayList<>();
        strings.parallelStream().forEach(str ->{
            if(str.indexOf("ERROR")>-1){
                String[] split = str.split("\\)");
                int i1 = split[0].lastIndexOf("]");
                if (i1>=0){
                    String key = split[0].substring(i1 + 1);
                    if (errorMap.get(key)==null){
                        errorMap.put(key,str);
                    }
                }
            }

        });
        errorMap.forEach((key,val) -> errorStr.add(key+"--->"+val));
        CollectionUtil.sort(errorStr,(o1, o2) -> {
            return o1.compareTo(o2);
        });
        FileUtil.appendLines(errorStr,"C:\\Users\\admin\\Desktop\\log\\2\\error\\catalina.out_error","utf-8");
    }

    public static void main2(String[] args) throws Exception {
        long l = System.currentTimeMillis();
        Future<List<String>> ss = getStrFuture();
        Thread.sleep(10000);
        System.out.println("方法外");
        System.out.println("ss的值为"+ss.get());
        System.out.println(System.currentTimeMillis()-l);

    }
    private static Future<List<String>> getStrFuture() throws Exception{
        Thread.sleep(10000);
        List<String> of = ListUtil.of("xx", "y");
        System.out.println("方法内");
        return new AsyncResult<>(of);
    }
}
